package com.lws.applicationlifecycle;

import android.app.Application;
import android.content.Context;

public class AppLifeCycle implements AppLifeCycleObserver {


    public static final String NAME = AppLifeCycle.class.getCanonicalName();
    private final ObserverList<AppLifeCycleObserver> observers = new ObserverList<>();
    private final ObserverList<Application> applications = new ObserverList<>();

    @Override
    public void attachBaseContext(Context base) {
        // do nothing
    }

    public final void addAppLifeCycleObserver(AppLifeCycleObserver observer) {
        observers.add(observer);
    }

    public final void addAppLifeCycleObserver(Application application) {
        applications.add(application);
    }

    public final void removeAppLifeCycleObserver(AppLifeCycleObserver observer) {
        observers.remove(observer);
    }

    public final void removeAppLifeCycleObserver(Application application) {
        observers.remove(application);
    }


    @Override
    public void onCreate() {
        observers.onCreate();
        applications.onCreate();
    }

    @Override
    public void onTerminate() {
        observers.onTerminate();
        applications.onTerminate();
    }
}
